﻿

using Shileme.Entity.Common;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Shileme.Common.Helper
{
    /// <summary>
    /// 枚举辅助类
    /// author      heyz
    /// </summary>
    public static class EnumHelper
    {

        /// <summary>
        /// 商品发布--来源
        /// </summary>
        public enum SellType : byte
        {
            [System.ComponentModel.Description("淘宝")]
            TaoBao = 1,

            [System.ComponentModel.Description("天猫")]
            TianMao = 2,

            [System.ComponentModel.Description("京东")]
            JinDong = 3,

            [System.ComponentModel.Description("拍拍")]
            PaiPai = 4
        }

        public enum compType : byte
        {
            [System.ComponentModel.Description("买家")]
            buyer = 1,

            [System.ComponentModel.Description("商家")]
            seller = 2,
        }

        /// <summary>
        /// 商品发布--类型
        /// </summary>
        public enum SellShi : byte
        {
            [System.ComponentModel.Description("搜索下单（电脑端）")]
            SS_PC = 1,

            [System.ComponentModel.Description("二维码下单 (手机下单)")]
            EW_Phone = 2,

            [System.ComponentModel.Description("搜索下单（手机端）")]
            SS_Phone = 3,

            [System.ComponentModel.Description("搜索下单（直通车）")]
            SS_ZTC = 4
        }

        /// <summary>
        /// 订单状态
        /// </summary>
        public enum OrderStatus : byte
        {
            [System.ComponentModel.Description("未填写订单号")]//待填订单
            WaitWriting = 0,
            [System.ComponentModel.Description("待审核订单")]
            Toaudit = 1,
            [System.ComponentModel.Description("申诉中")]
            Complaint = 2,
            [System.ComponentModel.Description("订单号有误")]
            ErrorOrder = 3,
            [System.ComponentModel.Description("订单已传截图")]
            GetImage = 4,

            [System.ComponentModel.Description("已关闭")]
            Close = 7,

            [System.ComponentModel.Description("已经结算")]
            Succeed = 8,


            [System.ComponentModel.Description("等传截图")]
            WaitImage = 9,

        }

        /// <summary>
        /// 商品试用状态
        /// </summary>
        public enum TrialApplyStatus : byte
        {
            [System.ComponentModel.Description("待审核")]
            Toaudit = 0,
            [System.ComponentModel.Description("通过审核")]
            SucceedAudit = 1,
            [System.ComponentModel.Description("审核拒绝")]
            Reject = 2,
            [System.ComponentModel.Description("商品已结算")]
            Close = 3,
            [System.ComponentModel.Description("已取消资格")]
            Cancel = 4,
           
        }

        /// <summary>
        /// 交易类型
        /// </summary>
        public enum Tradetype : byte
        {
            [System.ComponentModel.Description("新增金额")]
            addTrade=1,
            [System.ComponentModel.Description("冻结金额")]
            freeze=2,
           
            [System.ComponentModel.Description("扣除金额")]
            delTrade = 3

        }
        /// <summary>
        /// 任务类型
        /// </summary>
        public enum TaskNewType : byte
        {
            /// <summary>
            /// 拍A送A
            /// </summary>
            [System.ComponentModel.Description("拍A送A")]
            AtoATask = 0,
            /// <summary>
            /// 拍A送B
            /// </summary>
            [System.ComponentModel.Description("拍A送B")]
            AtoBTask = 1,
            /// <summary>
            /// 佣金任务
            /// </summary>
            [System.ComponentModel.Description("佣金任务")]
            CTask = 2
        }
        /// <summary>
        /// 任务类型
        /// </summary>
        public enum TaskType : byte
        {
            [System.ComponentModel.Description("试用任务")]
            TTask = 1,
            [System.ComponentModel.Description("佣金任务")]
            CTask = 2
        }


        /// <summary>
        /// 充值方式
        /// </summary>
        public enum RechargeType : byte
        {
            [System.ComponentModel.Description("网上银行")]
            Bank = 0,
            [System.ComponentModel.Description("支付宝")]
            ZhiFuBao = 1,
            [System.ComponentModel.Description("手动打款")]
            Auto = 2,
        }

        /// <summary>
        /// 充值打款方式
        /// </summary>
        public enum RechargeStatus : byte
        {
            [System.ComponentModel.Description("未打款")]
            Waiting = 0,
            [System.ComponentModel.Description("已关闭")]
            Closed = 1,
            [System.ComponentModel.Description("待审核")]
            Checking = 2,
            [System.ComponentModel.Description("已打款")]
            Success = 3,
        }


        /// <summary>
        /// 是否启用
        /// </summary>
        public enum IsUse : byte {
            [System.ComponentModel.Description("否")]
            No = 0,
            [System.ComponentModel.Description("是")]
            Yes = 1,
        }


        /// <summary>
        /// 提现类型
        /// </summary>
        public enum WithdrawType : byte {
            [System.ComponentModel.Description("网上银行")]
            Bank = 0,
            [System.ComponentModel.Description("支付宝")]
            Alipay = 1,
        }



        /// <summary>
        /// 提现状态
        /// </summary>
        public enum WithdrawStatus : byte
        {
            [System.ComponentModel.Description("提现审核")]
            WaitingCheck=0,
            [System.ComponentModel.Description("审核通过")]
            CheckPass = 1,
            /// <summary>
            /// 审核拒绝
            /// </summary>
            [System.ComponentModel.Description("审核拒绝")]
            CheckFail=2,
        }



        /// <summary>
        /// 发布商品--搜索下单(电脑端)|搜索下单(直通车) 关键词
        /// </summary>
        public enum BabyKeyWords : byte {
            [System.ComponentModel.Description("所有宝贝")]
            All = 1,
            [System.ComponentModel.Description("天猫")]
            TianMao = 2,
            [System.ComponentModel.Description("二手")]
            TwoHand = 3,
        }


        /// <summary>
        /// 发布商品--搜索下单(电脑端)|搜索下单(直通车)  关键字二级自雷
        /// </summary>
        public enum ItemFromBabyKeyWords : byte {
            [System.ComponentModel.Description("综合排序")]
            ZHPX = 1,
            [System.ComponentModel.Description("人气")]
            RQ = 2,
            [System.ComponentModel.Description("销量")]
            XL = 3,
        }


        /// <summary>
        /// 搜索下单（手机端） 关键字一级子类
        /// </summary>
        public enum KeyWordsFromSSXD_Phone {
            [System.ComponentModel.Description("综合排序")]
            ZHPX = 4,
            [System.ComponentModel.Description("价格低到高")]
            LowToHigh = 5,
            [System.ComponentModel.Description("价格高到低")]
            HighToLow = 6,
            [System.ComponentModel.Description("信用排序")]
            XYPX = 7,
            [System.ComponentModel.Description("销量优先")]
            XLYX = 8,
        } 


        /// <summary>
        /// 手机类型
        /// </summary>
        public enum PhoneType : byte {
            [System.ComponentModel.Description("手机淘宝App")]
            TaoBaoApp = 1,
            [System.ComponentModel.Description("手机天猫App")]
            TianMaoApp = 2,
        }


        /// <summary>
        /// 邮费
        /// </summary>
        public enum Postage : byte {
            [System.ComponentModel.Description("付邮")]
            Post = 0,
            [System.ComponentModel.Description("包邮")]
            Free = 1,
        }


        /// <summary>
        /// 旺旺黑名单禁用类型
        /// </summary>
        public enum ForbiddenType : byte {
            [System.ComponentModel.Description("淘宝账号")]
            TaoBao = 0,
        }



        /// <summary>
        /// 私信阅读状态
        /// </summary>
        public enum MessageStatus : byte {
            [System.ComponentModel.Description("未读")]
            UnRead = 0,
            [System.ComponentModel.Description("已读")]
            Read = 1,
        }


        /// <summary>
        /// 私信记录类型
        /// </summary>
        public enum MessageType : byte {
            [System.ComponentModel.Description("商品审核")]
            ProductCheck = 0,

            [System.ComponentModel.Description("商品投诉")]
            ProductComplaint = 1,

            [System.ComponentModel.Description("系统消息")]
            SystemMsg = 2,
            
        }


        /// <summary>
        /// 发布商品状态
        /// </summary>
        public enum TrailStatus : byte { 
            [System.ComponentModel.Description("待审核")]
            WaitingCheck = 0,

            [System.ComponentModel.Description("未通过审核")]
            CheckFail = 1,

            [System.ComponentModel.Description("审核通过")]
            CheckSuccess = 2,
             [System.ComponentModel.Description("已上架")]
            Up = 3,

            [System.ComponentModel.Description("已下架")]
            Down = 4,

            [System.ComponentModel.Description("已售完")]
            Finishi = 5,

            [System.ComponentModel.Description("待上架")]
            WaitUp = 6,
         
        }


        /// <summary>
        /// 是否推荐
        /// </summary>
        public enum IsReCommond : byte
        {
            [System.ComponentModel.Description("否")]
            No = 0,
            [System.ComponentModel.Description("是")]
            Yes = 1,
        }

        /// <summary>
        /// 是否首页展示
        /// </summary>
        public enum IsTop: byte
        {
            [System.ComponentModel.Description("否")]
            No = 0,
            [System.ComponentModel.Description("是")]
            Yes = 1,
        }

        /// <summary>
        /// 是否显示买家qq
        /// </summary>
        public enum IsShowQQ : byte
        {
            [System.ComponentModel.Description("不显示")]
            No = 0,
            [System.ComponentModel.Description("显示")]
            Yes = 1,
        }

        /// <summary>
        /// 记录日志类型 HT_RechargeLog
        /// </summary>
        public enum ReType : byte
        {
            /// <summary>
            /// 充值
            /// </summary>
            [System.ComponentModel.Description("充值")]
            Recharge = 0,
            /// <summary>
            /// 提现
            /// </summary>
            [System.ComponentModel.Description("提现")]
            Withdraw = 1,
            /// <summary>
            /// 转账
            /// </summary>
            [System.ComponentModel.Description("转账")]
            Accounts = 2,
        }

        /// <summary>
        /// 广告位置
        /// </summary>
        public enum ADShowPosType : byte
        {
            /// <summary>
            /// 首页顶部
            /// </summary>
            [System.ComponentModel.Description("首页顶部")]
            ADShowPosTopHead = 0,
            /// <summary>
            /// 首页轮播广告
            /// </summary>
            [System.ComponentModel.Description("首页轮播广告")]
            ADShowPosTopSlide = 1,
            /// <summary>
            /// 首页底部
            /// </summary>
            [System.ComponentModel.Description("首页底部")]
            ADShowPosTopBottom = 2,
            /// <summary>
            /// 免费试用轮播广告
            /// </summary>
            [System.ComponentModel.Description("免费试用轮播广告")]
            ADShowPosFreeTrySlide = 3
        }


        /// <summary>
        /// 文章所属
        /// </summary>
        public enum ArticleBelong : byte
        {
            /// <summary>
            /// 首页顶部
            /// </summary>
            [System.ComponentModel.Description("所有")]
            All = 0,
            /// <summary>
            /// 首页轮播广告
            /// </summary>
            [System.ComponentModel.Description("商家")]
            Seller = 1,
            /// <summary>
            /// 首页底部
            /// </summary>
            [System.ComponentModel.Description("刷手")]
            Buyer = 2,
     
        }
    }





    /// <summary>
    /// 基于.NET 2.0的枚举工具类
    /// </summary>
    public static class EnumToolV2
    {
        /// <summary>
        /// 从枚举中获取Description
        /// 说明：
        /// 单元测试-->通过
        /// </summary>
        /// <param name="enumName">需要获取枚举描述的枚举</param>
        /// <returns>描述内容</returns>
        public static string GetDescription(this Enum enumName)
        {
            string _description = string.Empty;
            FieldInfo _fieldInfo = enumName.GetType().GetField(enumName.ToString());
            DescriptionAttribute[] _attributes = _fieldInfo.GetDescriptAttr();
            if (_attributes != null && _attributes.Length > 0)
                _description = _attributes[0].Description;
            else
                _description = enumName.ToString();
            return _description;
        }
        /// <summary>
        /// 获取字段Description
        /// </summary>
        /// <param name="fieldInfo">FieldInfo</param>
        /// <returns>DescriptionAttribute[] </returns>
        public static DescriptionAttribute[] GetDescriptAttr(this FieldInfo fieldInfo)
        {
            if (fieldInfo != null)
            {
                return (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
            }
            return null;
        }
        /// <summary>
        /// 根据Description获取枚举
        /// 说明：
        /// 单元测试-->通过
        /// </summary>
        /// <typeparam name="T">枚举类型</typeparam>
        /// <param name="description">枚举描述</param>
        /// <returns>枚举</returns>
        public static T GetEnumName<T>(string description)
        {
            Type _type = typeof(T);
            foreach (FieldInfo field in _type.GetFields())
            {
                DescriptionAttribute[] _curDesc = field.GetDescriptAttr();
                if (_curDesc != null && _curDesc.Length > 0)
                {
                    if (_curDesc[0].Description == description)
                        return (T)field.GetValue(null);
                }
                else
                {
                    if (field.Name == description)
                        return (T)field.GetValue(null);
                }
            }
            throw new ArgumentException(string.Format("{0} 未能找到对应的枚举.", description), "Description");
        }
        /// <summary>
        /// 将枚举转换为ArrayList
        /// 说明：
        /// 若不是枚举类型，则返回NULL
        /// 单元测试-->通过
        /// </summary>
        /// <param name="type">枚举类型</param>
        /// <returns>ArrayList</returns>
        public static ArrayList ToArrayList(this Type type)
        {
            if (type.IsEnum)
            {
                ArrayList _array = new ArrayList();
                Array _enumValues = Enum.GetValues(type);
                foreach (Enum value in _enumValues)
                {
                    _array.Add(new KeyValuePair<Enum, string>(value, GetDescription(value)));
                }
                return _array;
            }
            return null;
        }

        public static List<EnumDto> ToEnumDtoList(Type type)
        {
            if (type.IsEnum)
            {
                List<EnumDto> _array = new List<EnumDto>();
                string[] names = Enum.GetNames(type);
                Array _enumValues = Enum.GetValues(type);

                foreach (Enum value in _enumValues)
                {
                    var dto = new EnumDto();
                    dto.ID = (Byte)value.GetHashCode();
                    dto.EngName = value.ToString();
                    dto.ChnName = GetDescription(value);
                    _array.Add(dto);
                }
                return _array;
            }
            return null;
        }


        public static string GetEnumChnNameByType(Type type, int id)
        {
            string ret = "";
            if (type.IsEnum)
            {
                Array _enumValues = Enum.GetValues(type);

                foreach (Enum value in _enumValues)
                {
                    if (value.GetHashCode() == id)
                    {
                        ret = GetDescription(value);
                        break;
                    }

                }
                return ret;
            }
            return ret;
        }

    }
}
